package myjava.algorithm.leetcode;

public class CompareVersion {
	//compare Version
	public static int compareVersion(String version1, String version2) {
        String[] s1 = version1.split("\\.");
        String[] s2 = version2.split("\\.");
        
        String[] maxLengthArray = s1;
        String[] minLengthArray = s2;
        int IsMax = 1;
        
        if(s1.length < s2.length)
        {
        	maxLengthArray = s2;
        	minLengthArray = s1;
        	IsMax = -1;
        }
               
        for(int i=0;i<minLengthArray.length;i++)
        {
        	if(Integer.parseInt(s1[i]) > Integer.parseInt(s2[i]))
        	{
        		return 1;
        	}
        	else if (Integer.parseInt(s1[i]) < Integer.parseInt(s2[i]))
        	{
				return -1;
			}
        }
        
        for(int i = minLengthArray.length;i<maxLengthArray.length; i++)
        {
        	if(Integer.parseInt(maxLengthArray[i]) > 0)
        		return IsMax;
        }
        
        return 0;
    }
	
	public static void main(String[] args)
	{
		System.out.println(compareVersion("2.2.4.56","1.3"));
	}
}
